package doctor

import (
	"github.com/bgmp/config"
	"github.com/bgmp/handler"
	"github.com/bgmp/middleware"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
)

func (b Base) GetPatients(c *gin.Context, req *GetPatientsRequest) *GetPatientsResponse {
	user, err := middleware.GetDoctor(c)
	if err != nil {
		handler.Errorf(c, err.Error())
		return nil
	}

	tr := model.TherapeuticRelationship{
		Doctor: user.ID,
	}
	err = tr.Get(config.DB)
	if err != nil {
		handler.Errorf(c, err.Error())
		return nil
	}
	var patients []*model.UserVO
	for _, patientId := range tr.Patients {
		user.ID = patientId
		err = user.Get(config.DB)
		if err == nil {
			patients = append(patients, user.GetUserVO())
		}
	}
	return &GetPatientsResponse{
		Patients: patients,
	}
}

type GetPatientsRequest struct {
}

type GetPatientsResponse struct {
	Patients []*model.UserVO `json:"patients"`
}
